package com.choosefine.it.common.utils;

import com.choosefine.it.common.def.ResultCode;
import com.choosefine.it.common.exception.RespExcption;

/**
 * 断言类,用于快速处理校验并抛出运行时异常,方便事物回滚
 * 
 * @desc
 * @author 戚羿辰
 * @Date 2017/01/07
 */
public class Assert {

	/**
	 * 断言为空
	 * @throws
	 */
	public static void assertNull(Object obj) {
		if (null != obj) {
			throw new RespExcption();
		}
	}

	/**
	 * 断言为空
	 * @throws
	 */
	public static void assertNull(Object obj, int code) {
		if (null != obj) {
			throw new RespExcption(code, ResultCode.MSG_FAILD);
		}
	}

	/**
	 * 断言为空
	 * @throws
	 */
	public static void assertNull(Object obj, String msg) {
		if (null != obj) {
			throw new RespExcption(ResultCode.FAILED, msg);
		}
	}

	/**
	 * 断言为空
	 * @throws
	 */
	public static void assertNull(Object obj, int code, String msg) {
		if (null != obj) {
			throw new RespExcption(code, msg);
		}
	}

	/**
	 * 断言不为空
	 * @throws
	 */
	public static void assertNotNull(Object obj) {
		if (null == obj) {
			throw new RespExcption();
		}
	}

	/**
	 * 断言不为空
	 * @throws
	 */
	public static void assertNotNull(Object obj, int code) {
		if (null == obj) {
			throw new RespExcption(code, ResultCode.MSG_FAILD);
		}
	}

	/**
	 * 断言不为空
	 * @throws
	 */
	public static void assertNotNull(Object obj, String msg) {
		if (null == obj) {
			throw new RespExcption(ResultCode.FAILED, msg);
		}
	}

	/**
	 * 断言不为空
	 * @throws
	 */
	public static void assertNotNull(Object obj, int code, String msg) {
		if (null == obj) {
			throw new RespExcption(code, msg);
		}
	}

	/**
	 * 断言相等
	 * @throws
	 */
	public static void assertTrue(boolean bool) {
		if (!bool) {
			throw new RespExcption();
		}
	}

	/**
	 * 断言相等
	 * @throws
	 */
	public static void assertTrue(boolean bool, int code) {
		if (!bool) {
			throw new RespExcption(code, ResultCode.MSG_FAILD);
		}
	}

	/**
	 * 断言相等
	 * @throws
	 */
	public static void assertTrue(boolean bool, String msg) {
		if (!bool) {
			throw new RespExcption(ResultCode.FAILED, msg);
		}
	}

	/**
	 * 断言相等
	 * @throws
	 */
	public static void assertTrue(boolean bool, int code, String msg) {
		if (!bool) {
			throw new RespExcption(code, msg);
		}
	}

	/**
	 * 断言不相等
	 * @throws
	 */
	public static void assertFalse(boolean bool) {
		if (bool) {
			throw new RespExcption();
		}
	}

	/**
	 * 断言不相等
	 * @throws
	 */
	public static void assertFalse(boolean bool, int code) {
		if (bool) {
			throw new RespExcption(code, ResultCode.MSG_FAILD);
		}
	}

	/**
	 * 断言不相等
	 * @throws
	 */
	public static void assertFalse(boolean bool, String msg) {
		if (bool) {
			throw new RespExcption(ResultCode.FAILED, msg);
		}
	}

	/**
	 * 断言不相等
	 * @throws
	 */
	public static void assertFalse(boolean bool, int code, String msg) {
		if (bool) {
			throw new RespExcption(code, msg);
		}
	}

	/**
	 * 字符串不允许为空
	 * @throws
	 */
	public static void assertStrNotNull(String str) {
		if (null == str || str.length() == 0) {
			throw new RespExcption();
		}
	}

	/**
	 * 字符串不允许为空
	 * @throws
	 */
	public static void assertStrNotNull(String str, int code) {
		if (null == str || str.length() == 0) {
			throw new RespExcption(code, ResultCode.MSG_FAILD);
		}
	}

	/**
	 * 字符串不允许为空
	 * @throws
	 */
	public static void assertStrNotNull(String str, String msg) {
		if (null == str || str.length() == 0) {
			throw new RespExcption(ResultCode.FAILED, msg);
		}
	}

	/**
	 * 字符串不允许为空
	 * @throws
	 */
	public static void assertStrNotNull(String str, int code, String msg) {
		if (null == str || str.length() == 0) {
			throw new RespExcption(code, msg);
		}
	}
	/**
	 * 断言相等
	 * @author 戚羿辰
	 * @Date 2017/01/07
	 * @throws
	 */
	public static void assertEqu(boolean bool, String msg) {
		if (!bool) {
			throw new RespExcption(ResultCode.FAILED, msg);
		}
	}
}